//决策树的头文件


#include <iostream>
#include <fstream>
#include <string.h>

#include "trainData.h"
#include "dsTree.h"
#include "fileLoad.h"
//using namespace std;


int adult();            //adult文件的测试
int car();              //car文件的测试
int expended();         //expended文件的测试


int main(int argc, char *argv[])
{
    (void)argc;
    (void)argv;

    expended();
    car();
    adult();

    return 0;
}


int adult()
{
    trainData d;
    adultFileLoad(&d, (char*)"adult.data.txt");
    dsTree t;
    t.creatTree(&d);
    char result[30];
    int all = 0;
    int succed = 0;

    trainData test;
    adultFileLoad(&test, (char*)"adult.test.ched.txt");
    valueItem* tmp = test.itemLib;
    while(tmp != NULL)
    {
        all ++;
        t.testTree(tmp, result);
        if(strcmp(result, tmp->getKeyValue((char*)"class")->valueStr)==0)
        {
            succed ++;
        }
        tmp = tmp->getNextItem();
    }
    std::cout << all << " : " << succed << " : " << (succed+0.0)/all << std::endl;
    return 1;
}
int car()
{
    trainData d;
    carFileLoad(&d, (char*)"car.data.txtTrain.txt");
    dsTree t;
    t.creatTree(&d);
    char result[30];
    int all = 0;
    int succed = 0;

    trainData test;
    carFileLoad(&test, (char*)"car.data.txttest.txt");
    valueItem* tmp = test.itemLib;
    while(tmp != NULL)
    {
        all ++;
        t.testTree(tmp, result);
        if(strcmp(result, tmp->getKeyValue((char*)"class")->valueStr)==0)
        {
            succed ++;
        }
        tmp = tmp->getNextItem();
    }
    std::cout << all << " : " << succed << " : " << (succed+0.0)/all << std::endl;
    return 1;
}

int expended()
{
    trainData d;
    expandedFileLoad(&d, (char*)"expanded.txt.txtTrain.txt");
    dsTree t;
    t.creatTree(&d);
    char result[30];
    int all = 0;
    int succed = 0;

    trainData test;
    expandedFileLoad(&test, (char*)"expanded.txt.txttest.txt");
    valueItem* tmp = test.itemLib;
    while(tmp != NULL)
    {
        all ++;
        t.testTree(tmp, result);
        if(strcmp(result, tmp->getKeyValue((char*)"class")->valueStr)==0)
        {
            succed ++;
        }
        tmp = tmp->getNextItem();
    }
    std::cout << all << " : " << succed << " : " << (succed+0.0)/all << std::endl;
    return 1;
}

